﻿using System;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
{
    class Win32Imported
    {
        [DllImport("vcrydcaller.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
        public extern static int vcrydMount(System.Text.StringBuilder fileName, byte desiredLetter);

        [DllImport("vcrydcaller.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
        public extern static int vcrydDismount(byte letter);

        [DllImport("USER32.DLL", EntryPoint = "BroadcastSystemMessageA", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
        public extern static int BroadcastSystemMessage(Int32 dwFlags, ref Int32 pdwRecipients, int uiMessage, int wParam, IntPtr lParam);

        [DllImport("shell32.dll")]
        public static extern uint SHFormatDrive(IntPtr hwnd, uint drive, uint fmtID, uint options);
    }

    enum DeviceType : uint
    {
        DBT_DEVTYP_OEM = 0x00000000,
        DBT_DEVTYP_DEVNODE = 0x00000001,
        DBT_DEVTYP_VOLUME = 0x00000002,
        DBT_DEVTYP_PORT = 0x00000003,
        DBT_DEVTYP_NET = 0x00000004
    }

    enum VolumeChangeFlags : ushort
    {
        DBTF_MEDIA = 0x0001,
        DBTF_NET = 0x0002
    }

    enum SHFormatFlags : uint
    {
        SHFMT_ID_DEFAULT = 0xFFFF,
        SHFMT_OPT_FULL = 0x1,
        SHFMT_OPT_SYSONLY = 0x2,
        SHFMT_ERROR = 0xFFFFFFFF,
        SHFMT_CANCEL = 0xFFFFFFFE,
        SHFMT_NOFORMAT = 0xFFFFFFD,
    }

    [StructLayout(LayoutKind.Sequential)]
    struct DEV_BROADCAST_VOLUME
    {
        public uint dbcv_size;
        public DeviceType dbcv_devicetype;
        public uint dbcv_reserved;
        public uint dbcv_unitmask;
        public VolumeChangeFlags dbcv_flags;
    }
}
